package logic

import (
	"context"
	"test-demo/model"

	"test-demo/goods_srv/goods"
	"test-demo/goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddGoodsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddGoodsLogic {
	return &AddGoodsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddGoodsLogic) AddGoods(in *goods.AddGoodsRequest) (*goods.Response, error) {
	// todo: add your logic here and delete this line
	good := model.Goods{
		GoodsName:  in.Goodsname,
		GoodsPrice: float64(in.Goodsprice),
		GoodsNum:   int(in.Goodsnum),
		Img:        in.Goodsimg,
		Status:     1,
	}
	res := model.CreateGoods(good)
	if res == (model.Goods{}) {
		return &goods.Response{
			Pong: "0",
		}, nil
	}
	return &goods.Response{
		Pong: "1",
	}, nil
}
